﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BLL;
using Common;
using Models;


namespace TeacherMS
{
    public partial class FormLogin : Form
    {
        public FormLogin()
        {
            InitializeComponent();
        }

        private void FormLogin_Load(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void buttonLogin_Click(object sender, EventArgs e)

        {
            var username = textBoxUserName.Text.Trim();
            var password = textBoxPassword.Text.Trim();

            TeacherService teacherService = new TeacherService();
            var user = teacherService.Select().FirstOrDefault(x => x.Name == username && x.Password == password);
            //StudentService studentService = new StudentService();
            //var count=studentService.Select().Count();
            //Console.WriteLine($"{count}*****************************************");
            if (user == null)
            {
                MessageBox.Show("用户名或密码错误！！！");
            }
            else
            {
                AppData.CurrentUser = user;
                DialogResult = DialogResult.OK;
                Close();
            }
          
        }
    }
}
